"""
Case Type   : GUC
Case Name   : 使用gs_guc set方法设置参数float_suffix_acceptance为无效值,合理报错
Create At   : 2024/10/15
Owner       : cr13
Description :
        1.查询float_suffix_acceptance默认值
        2.修改参数值为on
        3.恢复参数默认值
Expect      :
        1.显示默认值为on
        2.修改成功
        3.默认值恢复成功
History     :
"""
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger

LOG = Logger()
commonsh = CommonSH('dbuser')


class ClientConnection(unittest.TestCase):
    def setUp(self):
        LOG.info(
            '-----Opengauss_Function_Float_Case0001start-----')
        self.constant = Constant()

    def test_synchronize_seqscans(self):
        LOG.info('---步骤1:查询默认值---')
        sql_cmd = commonsh.execut_db_sql('''show
            float_suffix_acceptance;''')
        LOG.info(sql_cmd)
        self.res = sql_cmd.splitlines()[-2].strip()
        LOG.info('--步骤2:修改参数值为on--')
        result = commonsh.execute_gsguc('set',
                                        self.constant.GSGUC_SUCCESS_MSG,
                                        f"float_suffix_acceptance=on")
        self.assertTrue(result)

    def tearDown(self):
        LOG.info('---步骤3:清理环境---')
        sql_cmd = commonsh.execut_db_sql('''show float_suffix_acceptance;''')
        LOG.info(sql_cmd)
        result = commonsh.execute_gsguc('set',
                                        self.constant.GSGUC_SUCCESS_MSG,
                                        f"float_suffix_acceptance")

        msg = commonsh.restart_db_cluster()
        LOG.info(msg)
        status = commonsh.get_db_cluster_status()
        self.assertTrue("Degraded" in status or "Normal" in status)
        LOG.info(
            '-----Opengauss_Function_Float_Case0001finish----')

